package com.chapter17.demo7;


public class UserThreadLocal implements Runnable{
    @Override
    public void run() {
        System.out.printf("%s,当前id是：%d%n",Thread.currentThread().getName(),Resource.get());
        Resource.increment();
        Thread.yield();
        System.out.printf("%s,当前id是：%d%n",Thread.currentThread().getName(),Resource.get());
    }

    public static void main(String[] args) {
        //5个线程访问的ID值都是井然有序的，因为它们访问的ID值都是各自的副本。
        for (int i=0;i<5;i++){
            new Thread(new UserThreadLocal()).start();
        }
    }
}
